package daobeauty.proxy.spring;

import java.util.Collection;

import org.hibernate.SessionFactory;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.beans.factory.FactoryBean;
// TODO see org.springframework.transaction.interceptor.TransactionProxyFactoryBean
// TODO testen, ob das wirklich so geht
/**
 * Created 09.09.2008
 * @author M. Serhat Cinar
 *
 */
public class DaoBeautyProxyFactoryBean implements FactoryBean{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private DaoBeautyInterceptor interceptor = new DaoBeautyInterceptor();
	
	private Class proxyInterface;
	
	public void setProxyInterface(Class proxyInterface){
		this.proxyInterface = proxyInterface;
		this.interceptor.setInterfaces(new Class[]{proxyInterface});
	}
	
	public void setSessionFactory(SessionFactory sessionFactory){
		this.interceptor.setSessionFactory(sessionFactory);
	} 
	
	public void setDelegates(Collection delegates){
		this.interceptor.setDelegates(delegates);
	}
	
	public void setTarget(Object target){
		this.interceptor.setTarget(target);
	}
	
	public void setDomainClass(Class domainClass) {
		this.interceptor.setDomainClass(domainClass);
	}
	
	/* (non-Javadoc)
	 * @see org.springframework.beans.factory.FactoryBean#getObject()
	 */
	public Object getObject() throws Exception {
		if (proxyInterface==null){
			throw new IllegalArgumentException("no proxy interfaces defined");
		}
		this.interceptor.afterPropertiesSet();
		return ProxyFactory.getProxy(proxyInterface, this.interceptor);
	}
	
	/* (non-Javadoc)
	 * @see org.springframework.beans.factory.FactoryBean#getObjectType()
	 */
	public Class getObjectType() {
		return null;
	}

	/* (non-Javadoc)
	 * @see org.springframework.beans.factory.FactoryBean#isSingleton()
	 */
	public boolean isSingleton() {
		return true;
	}
}
